package com.ourchem.web.controller.bus;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ourchem.common.annotation.Log;
import com.ourchem.common.core.controller.BaseController;
import com.ourchem.common.core.domain.AjaxResult;
import com.ourchem.common.enums.BusinessType;
import com.ourchem.bus.domain.Lecturer;
import com.ourchem.bus.service.ILecturerService;
import com.ourchem.common.utils.poi.ExcelUtil;
import com.ourchem.common.core.page.TableDataInfo;

/**
 * lecturerController
 * 
 * @author xiYan
 * @date 2023-01-12
 */
@RestController
@RequestMapping("/lecturer/lecturer")
public class LecturerController extends BaseController
{
    @Autowired
    private ILecturerService lecturerService;

    /**
     * 查询lecturer列表
     */
    @PreAuthorize("@ss.hasPermi('lecturer:lecturer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Lecturer lecturer)
    {
        startPage();
        List<Lecturer> list = lecturerService.selectLecturerList(lecturer);
        return getDataTable(list);
    }

    /**
     * 导出lecturer列表
     */
    @PreAuthorize("@ss.hasPermi('lecturer:lecturer:export')")
    @Log(title = "lecturer", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Lecturer lecturer)
    {
        List<Lecturer> list = lecturerService.selectLecturerList(lecturer);
        ExcelUtil<Lecturer> util = new ExcelUtil<Lecturer>(Lecturer.class);
        return util.exportExcel(list, "lecturer数据");
    }

    /**
     * 获取lecturer详细信息
     */
    @PreAuthorize("@ss.hasPermi('lecturer:lecturer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lecturerService.selectLecturerById(id));
    }

    /**
     * 新增lecturer
     */
    @PreAuthorize("@ss.hasPermi('lecturer:lecturer:add')")
    @Log(title = "lecturer", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Lecturer lecturer)
    {
        return toAjax(lecturerService.insertLecturer(lecturer));
    }

    /**
     * 修改lecturer
     */
    @PreAuthorize("@ss.hasPermi('lecturer:lecturer:edit')")
    @Log(title = "lecturer", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Lecturer lecturer)
    {
        return toAjax(lecturerService.updateLecturer(lecturer));
    }

    /**
     * 删除lecturer
     */
    @PreAuthorize("@ss.hasPermi('lecturer:lecturer:remove')")
    @Log(title = "lecturer", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lecturerService.deleteLecturerByIds(ids));
    }
}
